package ycj.learn.dubbo;

import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;

import java.io.IOException;

public class ProviderTest {


    public static void main(String[] args) throws IOException {
        //设置应用名称
        ApplicationConfig config = new ApplicationConfig();
        config.setName("provider");

        //设置dubbo的协议
        ProtocolConfig protocolConfigDubbo = new ProtocolConfig();
        protocolConfigDubbo.setPort(12881);
        protocolConfigDubbo.setName("dubbo");

        //服务提供者暴露服务
        ServiceConfig<IHelloService> serviceServiceConfig = new ServiceConfig<>();
        serviceServiceConfig.setApplication(config);    //设置应用名称
        serviceServiceConfig.setRegistry(Configuration.registryConfig());     //设置注册中心
        serviceServiceConfig.setProtocol(protocolConfigDubbo);  //设置协议

        serviceServiceConfig.setInterface(IHelloService.class);      //设置接口
        serviceServiceConfig.setRef(new HelloService());        //设置具体实现类

        serviceServiceConfig.export();      //暴露和注册服务

        int read = System.in.read();
    }
}
